package com.hyts.standard.webflux.react.event;

import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Subscription;
import reactor.core.publisher.BaseSubscriber;
import reactor.core.publisher.Flux;

/**
 * @author wayne
 * @version CustSubscriber,  2020/9/3
 */
@Slf4j
public class EventSubscriber<T> extends BaseSubscriber<T> {

    /**
     * 订阅处理控制
     * @param subscription
     */
    @Override
    public void hookOnSubscribe(Subscription subscription) {
        log.info("subscribe the subscription info:{}",subscription);
        request(1);
    }

    /**
     * 下一个处理操作
     * @param value
     */
    @Override
    public void hookOnNext(T value) {
        log.info("subscribe the request info:{}",value);
        request(1);
    }

    /**
     * 完成处理操作
     */
    @Override
    protected void hookOnComplete() {
        log.info("subscribe the request info completed");
        super.hookOnComplete();
    }

    /**
     * 错误处理操作
     * @param throwable
     */
    @Override
    protected void hookOnError(Throwable throwable) {
        log.error("subscribe the request error",throwable);
        super.hookOnError(throwable);
    }

}
